﻿using System.Collections.Generic;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.ASPxEditors;
using Kaysite.Controller;
using Kaysite.Manager;
using Kaysite.Model;

public partial class Controls_AdminControls_OfficeEdit : BaseEditControl<OfficeManager, OfficeController, Office>
{
    protected override ASPxCallback GetCallbackControl()
    {
        return clbkSave;
    }

    protected override ASPxButton GetCancelButton()
    {
        return btnCancel;
    }

    protected override ASPxButton GetOkButton()
    {
        return btnOk;
    }

    protected override void DoInitialize_2_LoadDataInitControls()
    {
        base.DoInitialize_2_LoadDataInitControls();
        InitComboEnum<eRegion>(ddlRegion, e0Type.PlsSelect);
        InitComboEnum(ddlDisplayOption, e0Type.DontNeed,
            new List<eDisplayOption> {eDisplayOption.DisplayWithChild});
    }

    protected override void InitControlsByModelData(Office model)
    {
        if (model == null)
        {
            ddlDisplayOption.Value = (int)eDisplayOption.Hide;
            return;
        }
        txtName.Text = model.Name;
        ddlRegion.Value = (int)model.RegionID;
        txtCity.Text = model.City;
        txtAddress1.Text = model.Address;
        txtAddress2.Text = model.Address2;
        txtPhone1.Text = model.Phone1;
        txtPhone2.Text = model.Phone2;
        txtPhone3.Text = model.Phone3;
        txtPhone4.Text = model.Phone4;
        ddlDisplayOption.Value = (int)model.DisplayInMain;
    }

    protected override void LoadModelDataFromControls(Office model)
    {
        model.OfficeName = GetValue<string>(txtName);
        model.RegionID = GetValue<eRegion>(ddlRegion);
        model.City = GetValue<string>(txtCity);
        model.Address = GetValue<string>(txtAddress1);
        model.Address2 = GetValue<string>(txtAddress2);
        model.Phone1 = GetValue<string>(txtPhone1);
        model.Phone2 = GetValue<string>(txtPhone2);
        model.Phone3 = GetValue<string>(txtPhone3);
        model.Phone4 = GetValue<string>(txtPhone4);
        model.DisplayInMain = GetValue<eDisplayOption>(ddlDisplayOption);
    }
}